home *** CD-ROM | disk | FTP | other *** search
- /* ******************************************************************* */
- /* ** ** */
- /* ** ATKeyboard Version 4.0 ** */
- /* ** Copright (C) 1992-1994 by Thomas Dreibholz ** */
- /* ** All rights reserved ** */
- /* ** ** */
- /* ** Sprachausgabe ** */
- /* ** ** */
- /* ******************************************************************* */
-
- #include "ATKeyboard.h"
-
- EXTERN BOOL Speak;
- EXTERN UBYTE *TitelText;
- extern struct Menu Menu1;
- extern struct TextAttr OpalFontDef;
- extern struct Einstellungen Einstellungen;
- extern struct Window *WindowPtr;
-
- UBYTE Channels[]={3,5,10,12};
- UBYTE *TestText="A-T-Keyboard Narrator Device Test";
-
- UBYTE *SpeakBuffer;
- LONG NarratorDev=-1L;
- struct narrator_rb *NarratorReq;
- struct MsgPort *NarratorPort;
-
- LONG Div0();
-
-
- /* Text sprechen */
- VOID Say(text)
- UBYTE *text;
- {
- LONG error;
-
- if(NarratorDev==-1) return;
- if(Speak==FALSE) return;
-
- error=Translate(text,strlen(text),SpeakBuffer,1024);
- if(error==0)
- {
- NarratorReq->rate=Einstellungen.SpeakRate;
- NarratorReq->pitch=Einstellungen.SpeakPitch;
- NarratorReq->mode=Einstellungen.SpeakMode;
- NarratorReq->sex=Einstellungen.SpeakSex;
- NarratorReq->ch_masks=&Channels;
- NarratorReq->nm_masks=4;
- NarratorReq->volume=Einstellungen.SpeakVolume;
- NarratorReq->sampfreq=Einstellungen.SpeakFreq;
- NarratorReq->mouths=0;
- NarratorReq->message.io_Command=CMD_WRITE;
- NarratorReq->message.io_Data=SpeakBuffer;
- NarratorReq->message.io_Length=strlen(SpeakBuffer);
- DoIO(NarratorReq);
- }
- }
-
- /* Narrator installieren */
- BOOL InitNarrator()
- {
- SpeakBuffer=AllocMem(1024,MEMF_CLEAR|MEMF_PUBLIC);
- if(SpeakBuffer==NULL) return(FALSE);
- NarratorPort=CreatePort("ATKeyboard Narrator Port",0);
- if(NarratorPort==NULL) return(FALSE);
- NarratorReq=CreateExtIO(NarratorPort,sizeof(struct narrator_rb));
- if(NarratorReq==NULL) return(FALSE);
- NarratorDev=OpenDevice("narrator.device",0,NarratorReq,0);
- if(NarratorDev!=0) return(FALSE);
- return(TRUE);
- }
-
- /* Narrator entfernen */
- VOID RemoveNarrator()
- {
- if(NarratorDev==0)
- {
- Say("have a nice day");
- if( (CheckIO(NarratorReq)) != NULL) WaitIO(NarratorReq);
- CloseDevice(NarratorReq);
- }
- if(NarratorReq) DeleteExtIO(NarratorReq);
- if(NarratorPort) DeletePort(NarratorPort);
- if(SpeakBuffer) FreeMem(SpeakBuffer,1024);
- }
-
- UWORD oldw=0xFFFF,oldh,oldww,oldwh;
-
- VOID DrawMouth(win,w,h)
- struct Window *win;
- UWORD w,h;
- {
- REGISTER UWORD ww,wh;
- register struct RastPort *rp;
-
- rp=win->RPort;
-
- if(oldw!=0xFFFF)
- {
- SetAPen(rp,0);
- Move(rp,oldww-oldw,oldwh);
- Draw(rp,oldww,oldwh-oldh);
- Draw(rp,oldww+oldw,oldwh);
- Draw(rp,oldww,oldwh+oldh);
- Draw(rp,oldww-oldw,oldwh);
- }
-
- ww=(win->Width/2)-10;
- wh=(win->Height/2)-10;
-
- w*=ww/16;
- h*=wh/16;
-
- SetAPen(rp,3);
- WaitTOF();
- Move(rp,ww-w,wh);
- Draw(rp,ww,wh-h);
- Draw(rp,ww+w,wh);
- Draw(rp,ww,wh+h);
- Draw(rp,ww-w,wh);
-
- oldw=w;
- oldh=h;
- oldww=ww;
- oldwh=wh;
- }
-
- /* Narrator-Einstellungen */
- VOID NarratorPrefs()
- {
- UBYTE *Titel,error,*teststr;
- BOOL ende;
- ULONG Class;
- register struct Gadget *female,*robot,*gad,*freq,*rate,*pitch,*vol;
- register struct Window *win,*mwin;
- struct RastPort *rp,*mrp;
- register struct IntuiMessage *msg;
- register struct PropInfo *pi;
- struct mouth_rb *io;
- struct MsgPort *port;
-
- ClearMenuStrip(WindowPtr);
- Titel=WindowPtr->Title;
- SetWindowTitles(WindowPtr,TitelText,TitelText);
-
- win=CreateStdWindow("ATKeyboard - Sprachausgabeeinstellungen",
- 10,10,450,112,
- CLOSEWINDOW|GADGETUP,
- ACTIVATE|WINDOWDEPTH|WINDOWDRAG|WINDOWCLOSE);
- if(win!=NULL)
- {
- rp=win->RPort;
- SetFont(rp,GetOpalFont());
- SelectStdFPen(rp);
- WriteText(rp,15,25,"Frequenz:");
- freq=CreatePropGadget(win,150,15,280,12,Div0(65535*(Einstellungen.SpeakFreq-5000),23000),0,65535/23000,0,1);
- WriteText(rp,15,40,"Worte/Sek:");
- rate=CreatePropGadget(win,150,30,280,12,Div0(65535*(Einstellungen.SpeakRate-40),360),0,65535/360,0,2);
- WriteText(rp,15,55,"Grundtonhöhe:");
- pitch=CreatePropGadget(win,150,45,280,12,Div0(65535*(Einstellungen.SpeakPitch-65),255),0,65535/255,0,3);
- WriteText(rp,15,70,"Lautstärke:");
- vol=CreatePropGadget(win,150,60,280,12,Div0(65535*Einstellungen.SpeakVolume,64),0,65535/64,0,30);
- if(Einstellungen.SpeakSex==1)
- female=CreateSToggleGadget(win,15,75,180,12,"weibliche Stimme",4);
- else
- female=CreateNToggleGadget(win,15,75,180,12,"weibliche Stimme",4);
- if(Einstellungen.SpeakMode==1)
- robot=CreateSToggleGadget(win,250,75,180,12,"roboterhafte Stimme",5);
- else
- robot=CreateNToggleGadget(win,250,75,180,12,"roboterhafte Stimme",5);
- CreateBoolGadget(win,15,90,50,12,"Test",10);
- teststr=CreateStringGadget(win,70,90,360,12,TestText,256,11);
-
- port=CreatePort("ATKeyboard Narrator Mouthshape Port",0);
- if(port!=NULL)
- {
- io=CreateExtIO(port,sizeof(struct mouth_rb));
- if(io!=NULL)
- {
- io->voice.message.io_Device=NarratorReq->message.io_Device;
- io->voice.message.io_Unit=NarratorReq->message.io_Unit;
- io->voice.message.io_Unit->unit_flags=NarratorReq->message.io_Unit->unit_flags;
- mwin=CreateStdWindow("Test",445,110,190,95,
- 0,
- WINDOWDEPTH|WINDOWDRAG|WINDOWSIZING|SMART_REFRESH|GIMMEZEROZERO);
- if(mwin!=NULL)
- {
- mwin->MinWidth=50;
- mwin->MinHeight=30;
- mwin->MaxWidth=640;
- mwin->MaxHeight=256;
- mrp=mwin->RPort;
- SetAPen(mrp,3);
- DrawMouth(mwin,10,0);
- }
- }
- }
- rp=win->RPort;
- ende=FALSE;
- while(ende==FALSE)
- {
- WaitPort(win->UserPort);
- msg=GetMsg(win->UserPort);
- Class=msg->Class;
- gad=msg->IAddress;
- ReplyMsg(msg);
- switch(Class)
- {
- case GADGETUP:
- pi=freq->SpecialInfo;
- Einstellungen.SpeakFreq=(UWORD)Div0(pi->HorizPot*23000L,65535L)+(UWORD)5000;
- pi=pitch->SpecialInfo;
- Einstellungen.SpeakPitch=(UWORD)Div0(pi->HorizPot*255L,65535L)+(UWORD)65;
- pi=rate->SpecialInfo;
- Einstellungen.SpeakRate=(UWORD)Div0(pi->HorizPot*360L,65535L)+(UWORD)40;
- pi=vol->SpecialInfo;
- Einstellungen.SpeakVolume=(UWORD)Div0(pi->HorizPot*64L,65535L);
- if(female->Flags & SELECTED)
- Einstellungen.SpeakSex=1;
- else
- Einstellungen.SpeakSex=0;
- if(robot->Flags & SELECTED)
- Einstellungen.SpeakMode=1;
- else
- Einstellungen.SpeakMode=0;
- switch(gad->GadgetID)
- {
- case 10:
- error=Translate(teststr,strlen(teststr),SpeakBuffer,1024);
- if(error==0)
- {
- NarratorReq->rate=Einstellungen.SpeakRate;
- NarratorReq->pitch=Einstellungen.SpeakPitch;
- NarratorReq->mode=Einstellungen.SpeakMode;
- NarratorReq->sex=Einstellungen.SpeakSex;
- NarratorReq->ch_masks=&Channels;
- NarratorReq->nm_masks=4;
- NarratorReq->volume=Einstellungen.SpeakVolume;
- NarratorReq->sampfreq=Einstellungen.SpeakFreq;
- NarratorReq->message.io_Command=CMD_WRITE;
- NarratorReq->message.io_Data=SpeakBuffer;
- NarratorReq->message.io_Length=strlen(SpeakBuffer);
- if(mwin!=NULL)
- {
- NarratorReq->mouths=1;
- io->width=0;
- io->height=0;
- io->voice.message.io_Command=CMD_READ;
- io->voice.message.io_Error=0;
- if( (SendIO(NarratorReq)) == 0)
- {
- while(io->voice.message.io_Error != ND_NoWrite)
- {
- DoIO(io);
- DrawMouth(mwin,io->width,io->height);
- }
- }
- }
- else
- {
- NarratorReq->mouths=0;
- DoIO(NarratorReq);
- }
- }
- break;
- }
- break;
- case CLOSEWINDOW:
- ende=TRUE;
- break;
- }
- }
- if(mwin) DeleteStdWindow(mwin);
- if(io) DeleteExtIO(io);
- if(port) DeletePort(port);
- DeleteStdWindow(win);
- }
- SetWindowTitles(WindowPtr,Titel,TitelText);
- SetMenuStrip(WindowPtr,&Menu1);
- }
-
- /* Division mit 0-Abfrage */
- LONG Div0(a,b)
- LONG a,b;
- {
- if(b==0) return(0);
- return(a/b);
- }
-
-